'''
Created on Apr 28, 2012

@author: lavang
'''
import unittest
from Interface.modulePage import xpathModule, xpathLinkInstallModule,\
    xpathTxtPath, xpathBtnUpload, xpathChkOverwriteFolder
from selenium.webdriver.support.wait import WebDriverWait


def clickOnModule(self):
    browser=self.browser
    element=browser.find_element_by_xpath(xpathModule())
    element.click()
    
# click on link Install Module
def clickOnLinkInstallModule(self):
    browser=self.browser
    element=browser.find_element_by_xpath(xpathLinkInstallModule())
    element.click()
    
# Install Module
def installModule(self,filePath,overwriteFolder='on'):
    browser=self.browser
    element=browser.find_element_by_xpath(xpathTxtPath())
    element.send_keys(filePath)
    element=browser.find_element_by_xpath(xpathChkOverwriteFolder())
    if overwriteFolder=='on':
        if element.is_selected():
            pass
        else:
            element.click()
    element=browser.find_element_by_xpath(xpathBtnUpload())
    element.click()

# Verify module is installed
def isModuleInstalled(self,moduleName):
    browser = self.browser
    try:
        WebDriverWait(browser,20).until(lambda browser : browser.find_element_by_xpath(".//td[text()='"+moduleName+"']"))
        return True
    except:
        return False

# delete module
def deleteModule(self,moduleName):
    browser=self.browser
    element=browser.find_element_by_xpath("//td[text()='"+moduleName+"']/../td[6]/img[@alt='Delete']")
    element.click()
    alert=browser.switch_to_alert()
    alert.accept()
    browser.refresh()
    
# verify delete
def isModuleDelete(self,moduleName):
    browser = self.browser
    try:
        WebDriverWait(browser,20).until(lambda browser : browser.find_element_by_xpath(".//td[text()='"+moduleName+"']"))
        return True
    except:
        return False